﻿package
{
	import flash.display.Shader;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.external.ExternalInterface;
	import flash.net.SharedObject;
	import flash.system.Security;
	import flash.system.System;
	
	public class XINStore extends Sprite
	{
		public function XINStore()
		{
			Security.allowDomain("*");
			Security.allowInsecureDomain("*");
			
			ExternalInterface.addCallback( "xGet", xGet );
			ExternalInterface.addCallback( "xSet", xSet );
			ExternalInterface.addCallback( "xRemove", xRemove );
			ExternalInterface.addCallback( "xClear", xClear );
		}
		
		private function exportFunctions():void{
		}
		
		public function xGet( xName:String, key:String ):String{
			var xValue:String = "";
			try{
				var obj:SharedObject = SharedObject.getLocal( xName );
				xValue = obj.data[ key ];
			}catch( error:Error ){
				xValue = "";
			}
			return xValue;
		}
		public function xSet( xName:String, key:String, value:String ):void{
			try{
				var obj:SharedObject = SharedObject.getLocal( xName );
				obj.data[ key ] = value;
				obj.flush();
			}catch( error:Error ){
			}
		}
		public function xRemove( xName:String, key:String ):String{
			var xValue:String = "";
			try{
				var obj:SharedObject = SharedObject.getLocal( xName );
				var value:String = obj.data[ key ];
				delete obj.data[ key ];
				obj.flush();
			}catch( error:Error ){
				xValue = "";
			}
			return xValue;
		}
		public function xClear( xName:String ):void{
			try{
				var obj:SharedObject = SharedObject.getLocal( xName );
				obj.clear();
				obj.flush();
			}catch( error:Error ){
			}
		}
	}
}